using System;
using System.Collections.Generic;
using UnityEngine;

public class GameplayAchievementButton : MonoBehaviour
{
	[Serializable]
	public class Stage
	{
		public UILabel label;

		public GameObject baseObject;

		public BarSliderControl slider;
	}

	public UILabel title;

	public UILabel subtitle;

	public UILabel totalAchieved;

	public List<Stage> stages = new List<Stage>();

	private GameplayAchievement myAchievement;

	public void Init(GameplayAchievement achievement)
	{
		myAchievement = achievement;
		UITools.ChangeText(title, achievement.name);
		UITools.ChangeText(subtitle, achievement.description);
		UITools.ChangeText(totalAchieved, achievement.achievedStagesCount + "/" + achievement.totalStages);
		Debug.Log("ACHIEVEMENT: " + achievement.name);
		Debug.Log("total stages: " + achievement.totalStages);
		if (achievement.totalStages <= 1)
		{
			foreach (Stage stage in stages)
			{
				stage.baseObject.SetActive(false);
			}
		}
		else
		{
			for (int i = 0; i < stages.Count; i++)
			{
				if (achievement.totalStages > i)
				{
					stages[i].baseObject.SetActive(true);
					UITools.ChangeText(stages[i].label, achievement.GetStageText(i));
					int num = (achievement.HasCompletedStage(i) ? 1 : 0);
					stages[i].slider.UpdateSlider(num);
				}
				else
				{
					stages[i].baseObject.SetActive(false);
				}
			}
		}
		if (achievement.shouldShowAchievementStageCompleted)
		{
			GGStoryAchivementsController.instance.AchievementAccomplishedNotify(achievement);
		}
	}
}
